feat: Make CozyPouchLink compatible with ReactNative#1483
Merged
Ldoppea merged 6 commits intofeat/meta_offlinefrom Sep 9, 2024
Merged
feat: Make CozyPouchLink compatible with ReactNative#1483Ldoppea merged 6 commits intofeat/meta_offlinefrom
Ldoppea merged 6 commits intofeat/meta_offlinefrom
Conversation
6fe85a7 to
cb0062d
Compare
2 tasks
ca6071c to
bdea993
Compare
This was referenced May 31, 2024
paultranvan
reviewed
Jun 4, 2024
| export class PouchLocalStorage { | ||
| constructor(storageEngine) { | ||
| this.storageEngine = storageEngine | ||
| } |
Contributor
There was a problem hiding this comment.
Maye it would be worth checking the expected methods getItem, setItem, removeItem are provided by the storage engine ?
| ) | ||
| this.PouchDB = options.platform?.pouchAdapter || platformWeb.pouchAdapter | ||
| this.isOnline = options.platform?.isOnline || platformWeb.isOnline | ||
| this.events = options.platform?.events || platformWeb.events |
Contributor
There was a problem hiding this comment.
I wonder if we should enforce some strict checking on the given options.platform as it has a lot of responsibility and it's easy to miss something
| // as it avoids to replicate all revs history, which can lead to | ||
| // performances issues | ||
| docs = await replicateAllDocs(pouch, url, doctype) | ||
| docs = await replicateAllDocs(pouch, url, doctype, storage) |
Contributor
There was a problem hiding this comment.
nit: I might be worth moving to await replicateAllDocs({pouch, url, doctype, storage})
c376d72 to
255e57e
Compare
Base automatically changed from
feat/enable_type_generation_pouch
to
feat/meta_offline
July 26, 2024 14:41
16237f8 to
0049a23
Compare
We want to reduce coupling between CozyPouchLink and the browser's local storage The first step is to groupe existing methods into a PouchLocalStorage class, this will allow (in the next commit) to inject a storage adapter into the class constructor Also in some platforms like ReactNative, the localstorage methods are asynchronous. So in order to be compatible with all platforms we want those methods to become async by default The big main of making those methods async is that we cannot call them from the `PouchManager` constructor. So we introduce a new `.init()` method in the `PouchManager` class. This async method now contains all the initialization logic and should be called after creating a new `PouchManager` As `PouchManager` is called internally by `CozyPouchLink` and is not meant to be a publicly available class, then we don't consider this as a breaking change
We want to reduce coupling between CozyPouchLink and the browser's
local storage
This will allow to use CozyPouchLink from a react-native project where
`window.localStorage` API is not available
If no custom storage is injected, then `platformWeb.js` will be used by
default
In order to inject a custom storage, create a new platform object
containing the same API as `platformWeb.js` and add it into the
PouchLink constructor's `platform` option
```js
import { default as PouchLink } from 'cozy-pouch-link'
// Class based on `platformWeb.js`
import { CustomPlaftorm } from './CustomPlaftorm'
const pouchLink = new PouchLink({
platform: new CustomPlaftorm()
})
```
In previous commit we added a `platform` option into the PouchLink constructor in order to allow injecting a custom local storage API from a react-native project We also want to inject a custom PouchDB adapter as a react-native project would use a different PouchDB implementation Like for the local storage API, if no injection is given, then `pouchdb-browser` adapter will be used by default
In previous commit we added a `platform` option into the PouchLink constructor in order to allow injecting custom local storage API and PouchDB adapter from a react-native project We also want to inject a custom `isOnline` method as react-native does not provide the `window.navigator.onLine` API Like for the other APIs, if no injection is given, then `window.navigator.onLine` will be used by default
In previous commit we added a `platform` option into the PouchLink constructor in order to allow injecting custom local storage API, PouchDB adapter and isOnline method from a react-native project We also want to inject a custom evant emitter for online/offline and pause/resume events as react-native does not provide the `document.addEventListener` and `document.removeEventListener` APIs Like for the other APIs, if no injection is given, then `document` APIs will be used by default
255e57e to
0037e6f
Compare
paultranvan
approved these changes
Aug 12, 2024
Contributor
paultranvan
left a comment
There was a problem hiding this comment.
Excellent work, with very good atomic commits and descriptions!
Ldoppea
added a commit
that referenced
this pull request
Sep 4, 2024
In order to prevent implementation errors, we want to check that storageEngine implements the correct methods This replies to #1483 (comment)
Ldoppea
added a commit
that referenced
this pull request
Sep 4, 2024
Ldoppea
added a commit
that referenced
this pull request
Sep 9, 2024
In order to prevent implementation errors, we want to check that storageEngine implements the correct methods This replies to #1483 (comment)
Ldoppea
added a commit
that referenced
this pull request
Sep 9, 2024
Ldoppea
added a commit
that referenced
this pull request
Sep 9, 2024
In order to prevent implementation errors, we want to check that storageEngine implements the correct methods This replies to #1483 (comment)
Ldoppea
added a commit
that referenced
this pull request
Sep 9, 2024
Ldoppea
added a commit
that referenced
this pull request
Sep 9, 2024
In order to prevent implementation errors, we want to check that storageEngine implements the correct methods This replies to #1483 (comment)
Ldoppea
added a commit
that referenced
this pull request
Sep 9, 2024
Ldoppea
added a commit
that referenced
this pull request
Sep 19, 2024
In order to prevent implementation errors, we want to check that storageEngine implements the correct methods This replies to #1483 (comment)
Ldoppea
added a commit
that referenced
this pull request
Sep 19, 2024
Ldoppea
added a commit
that referenced
this pull request
Sep 19, 2024
In order to prevent implementation errors, we want to check that storageEngine implements the correct methods This replies to #1483 (comment)
Ldoppea
added a commit
that referenced
this pull request
Sep 19, 2024
Ldoppea
added a commit
that referenced
this pull request
Sep 24, 2024
In order to prevent implementation errors, we want to check that storageEngine implements the correct methods This replies to #1483 (comment)
Ldoppea
added a commit
that referenced
this pull request
Sep 24, 2024
Ldoppea
added a commit
that referenced
this pull request
Sep 24, 2024
In order to prevent implementation errors, we want to check that storageEngine implements the correct methods This replies to #1483 (comment)
Ldoppea
added a commit
that referenced
this pull request
Sep 24, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We want to reduce coupling between CozyPouchLink and the browser's
local storage
This PR adds a
platformoption into the PouchLink constructor inorder to allow injecting custom local storage API, PouchDB adapter, an
isOnline method and a custom event emitter for online/offline and
pause/resume events from the consuming app
This will allow to use CozyPouchLink from a react-native project where
a different PouchDB adapter is used and where none of
window.localStorage,window.navigator.onLine,document.addEventListeneranddocument.removeEventListenerAPI areavailable
If no custom
platformis injected, thenplatformWeb.jswill be usedby default
In order to inject a custom
platform, create a new platform objectcontaining the same API as
platformWeb.jsand add it into thePouchLink constructor's
platformoptionRelated PRs: